package integration;

import misc.Function;
import misc.IntgrationFunction;
import utils.math.MathCodes;
import MyFile.FileHandler;

public class IntegrationNonAdaptive {

    public static double calcIntegration(IntgrationFunction f1, Function f2,
	    double a, double b) {
	FileHandler.openFile("Graph");
	FileHandler.openNewSheet("first");
	FileHandler.addNewLable("numberOfPanles");
	FileHandler.addNewLable("Error");
	// I- real integral
	double integrationRealValue = (f1.integrationAtRange(a, b));
	int tempPanelsCount = 1;
	double tolerance = Math.pow(10, -15);
	// Im - result from division to m panels
	double integrationResultByPanels;
	double estimetedError;
	do {
	    integrationResultByPanels = MathCodes.calculateIntegralBR(f2, a, b,
		    tempPanelsCount);
	    estimetedError = Math.abs(integrationRealValue
		    - integrationResultByPanels);

	    FileHandler.addNewFloatValue(0, tempPanelsCount, tempPanelsCount);
	    FileHandler.addNewFloatValue(1, tempPanelsCount, estimetedError);

	    System.out.println(estimetedError);
	    tempPanelsCount++;
	} while (estimetedError > tolerance & tempPanelsCount < 10000);

	FileHandler.closeFile();
	return integrationResultByPanels;

    }
}
